import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const c = () => import(/* webpackChunkName: "group-zz" */'views/transition/c.vue')

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: require('views/index.vue').default
    },
    {
      path: '/bag',
      component: require('views/css/bag.vue').default
    },
    {
      path: '/file',
      component: require('views/learn/file.vue').default
    },
    {
      path: '/user',
      component: require('views/router/index.vue').default,
      // redirect: '/user/admin',
      props: {user: 'admin'},
      alias: '/admin' // 别名
    },
    {
      path: '/user/:user',
      component: require('views/router/user.vue').default,
      props: true,
      children: [
        { path: '', component: require('views/router/img.vue').default },
        {
          path: 'img/:img',
          name: 'img',
          component: require('views/router/img.vue').default,
          components: {
            default: require('views/router/img.vue').default,
            user: require('views/router/img.vue').default,
            vip: require('views/router/img_vip.vue').default
          }
        },
        {
          path: 'imgVip',
          name: 'imgVip',
          meta: {
            needVip: true
          },
          component: require('views/router/img_vip.vue').default
        }
      ]
    },
    { path: '/promise', component: require('views/learn/promise.vue').default },
    { path: '/transition',
      component: require('views/transition/index.vue').default,
      children: [
        { path: 'a', component: require('views/transition/a.vue').default },
        { path: 'b', component: require('views/transition/b.vue').default },
        { path: 'c', component: c }
      ]
    },
    { path: '/arguments', component: require('views/learn/arguments.vue').default },
    { path: '/store', component: require('views/store/index.vue').default },
    { path: '/infiniteLoading', component: require('views/css/infiniteLoading.vue').default },
    { path: '/gradual', component: require('views/css/gradual.vue').default },
    { path: '/arr', component: require('views/learn/arr.vue').default },
    { path: '*', component: require('views/error/404.vue').default }
  ],
  // savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用。
  scrollBehavior (to, from, savedPosition) {
    // if (to.path === '/transition/b') {
    //   console.log(savedPosition)
    //   return { x: 0, y: 0 } // 回到顶部
    //   // return { x: 0, y: 1000 }
    // }
  }
})
